/* when the page has finished loading.. execute the follow */
$(document).ready(function () {
    jQuery("#officeCallList").jqGrid({
        url:'/officeCall/listAsJSON?companyId=' + companyId,
        datatype: "json",
        colNames:['Company Name', 'Contact Name', 'Rep Name', 'Contact Type', 'Date', 'Notes', 'id'],
        colModel:[
            {name:'companyName', width:200},
            {name:'contactName', width:110},
            {name:'repName', width:110},
            {name:'contactType', width:80},
            {name:'date', width:120, formatter:'date', formatoptions: {srcformat:'y-m-d', newformat:'M-d-Y D g:i A'}},
            {name:'notes', width:300},
            {name:'id', hidden:true}
        ],
        altRows: true,
        autowidth: true,
        height: 332,
        message: 'The data is not available. Please refresh the screen.',
        pager: '#officeCallListPager',
        rowList: [20, 50, 75, 100],
        rowNum: 20,
        shrinkToFit: false,
        subGrid: false,
        viewrecords: true,
        onSelectRow: function(id) {
            window.location = "show/" + id
        }
    });
    jQuery("#officeCallList").jqGrid('gridResize',{minWidth:850,minHeight:80, maxHeight:600});
});

var timeoutHnd;
var type;

function doSearch(ev) {
    if (timeoutHnd) {
        clearTimeout(timeoutHnd)
    }
    timeoutHnd = setTimeout(gridReload,500)
}

function gridReload() {
    var searchValue = jQuery("#personSearch").val();
    jQuery("#personList").jqGrid('setGridParam', {url:"listPeopleAsJSON?searchValue=" + searchValue, page:1}).trigger("reloadGrid");
}
